#include "Common.h"
#include "MovableObject.h"
#include "SceneNode.h"


MovableObject::MovableObject(const std::string& name, Scene* owner)
	: mName(name)
	, mOwner(owner)
	, mParent(NULL)
	, mVisible(true)
{
}

MovableObject::~MovableObject(void)
{
	if (mParent != NULL)
		mParent->Dettach(this);
}

void MovableObject::NotifyAttached(SceneNode* parent)
{
	assert((parent == NULL || mParent == 0) && "You should dettach my first before attach to a scene node.");

	mParent = parent;

	if (parent != NULL)
		AddToScene();
	else
		RemoveFromScene();
}

void MovableObject::AddToScene()
{
	// add renderable object to the scene.
}

void MovableObject::RemoveFromScene()
{
	// remove renderable object from the scene.
}

void MovableObject::UpdateTransform()
{
	if (mParent)
	{
		mWorldAABB = getAABB();
		mWorldAABB.TransformAffine(mParent->getCachedMatrix());
	}
}